#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
using i128 = __int128;
using namespace std;

// 找到第一个黑色的位置和最后一个黑色的位置，计算中间的长度即可
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t, n;
    string s;
    cin >> t;
    while (t--){
        cin >> n >> s;

        int i = 0, j = n - 1;

        while(i < n && s[i]=='W') i++;
        while(j >= 0 && s[j]=='W') j--;

        if (j < i) {
            cout << "0" << endl;
        }else{
            cout << (j - i + 1) << endl;
        }
    }

    return 0;
}